using System;
using System.Collections.Generic;
using System.Text;
using Rest;
using Rest.Http;
using System.Drawing;

namespace Coriander.Google.Charting
{
    /// <summary>
    /// Represents background fill color
    /// </summary>
    public class ChartFill : IRestParameter
    {
        const String RestParameterName = "chf";

        ChartFillType chartFillType = ChartFillType.ChartArea;

        Color fillColor;

        /// <summary>
        /// Gets or sets the chart fill type
        /// </summary>
        public ChartFillType ChartFillType
        {
            get { return chartFillType; }
            set { chartFillType = value; }
        }

        /// <summary>
        /// The fill color to use
        /// </summary>
        public Color FillColor
        {
            get { return fillColor; }
            set { fillColor = value; }
        }

        /// <summary>
        /// Gets the value of the current instance
        /// </summary>
        /// <returns></returns>
        protected virtual String GetValue() 
        {
            return String.Format(
                "{0},s,{1}",
                ChartFillType,
                ChartColor.ToHtml(FillColor, true)
            );   
        }

        /// <summary>
        /// Sets the current value
        /// </summary>
        /// <param name="value"></param>
        protected virtual void SetValue(String value) 
        {
            if (null == value)
                throw new ArgumentNullException("value");
 
            FillColor = ColorTranslator.FromHtml(value);  
        }

        /// <summary>
        /// ctor
        /// </summary>
        public ChartFill() {}

        /// <summary>
        /// ctor : Color
        /// </summary>
        /// <param name="fillColor"></param>
        public ChartFill(Color fillColor) 
        {
            this.fillColor = fillColor; 
        }

        #region IRestParameter Members

        /// <summary>
        /// The RestParameter name for instances of ChartFill
        /// </summary>
        public string Name
        {
            get
            {
                return RestParameterName;
            }
            set
            {
                throw new NotSupportedException(
                    "ChartFill does not support setting the RestParameter name."
                );
            }
        }

        /// <summary>
        /// A hex color value, for example "#FFFFFF".
        /// </summary>
        public string Value
        {
            get
            {
                return GetValue();  
            }
            set
            {
                SetValue(value);   
            }
        }

        /// <summary>
        /// Gets an array of bytes representing the current instance
        /// </summary>
        /// <returns></returns>
        public Byte[] GetBytes()
        {
            throw new NotSupportedException("This type does not support this operation");
        }

        #endregion
    }
}
